unit fmck_StuffCheckPos;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, fmNormal, StdCtrls, DBGridEhGrouping, ToolCtrlsEh,
  DBGridEhToolCtrls, DynVarsEh, GridsEh, DBAxisGridsEh, DBGridEh, Buttons,
  DB, ADODB;

type
  Tfrmck_StuffCheckPos = class(TfrmNormal)
    Label1: TLabel;
    DBGridEh1: TDBGridEh;
    btnOK: TBitBtn;
    btnCancel: TBitBtn;
    adsPosList: TADODataSet;
    dsPosList: TDataSource;
    adsPosListSelected: TBooleanField;
    adsPosListPosID: TStringField;
    adsPosListPosNo: TStringField;
    adsPosListPosName: TStringField;
    btnALL: TBitBtn;
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure DBGridEh1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumnEh; State: TGridDrawState);
    procedure btnALLClick(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    FStockID: string;
    FPosList: string;
  end;

var
  frmck_StuffCheckPos: Tfrmck_StuffCheckPos;

implementation

uses dmConnect, uMsgBox, uGlobal, uShare;

{$R *.dfm}

procedure Tfrmck_StuffCheckPos.FormShow(Sender: TObject);
begin
  inherited;
  try
    DoBusy(True);
    with adsPosList do
    try
      Active := False;
      Parameters.ParamByName('DeptID').Value := SysInfo.Company;
      Parameters.ParamByName('StockID').Value := FStockID;
      Active := True;
    except
      raise;
    end;
  finally
    DoBusy(False);
  end;
end;

procedure Tfrmck_StuffCheckPos.FormCreate(Sender: TObject);
begin
  inherited;
  uShare.SetDBGridStyle(DBGridEh1);
end;

procedure Tfrmck_StuffCheckPos.DBGridEh1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumnEh;
  State: TGridDrawState);
begin
  inherited;
  uShare.SetDBGridColor(Sender, DataCol, Rect, Column, State);
end;

procedure Tfrmck_StuffCheckPos.btnALLClick(Sender: TObject);
begin
  inherited;
  with dsPosList.DataSet do
  begin
    while not Eof do
    begin
      Edit;
      FieldByName('Selected').AsBoolean := True;
      Next;
    end;
  end;
end;

procedure Tfrmck_StuffCheckPos.btnOKClick(Sender: TObject);
var
  PosList: string;
begin
  inherited;
  PosList := '';
  FPosList := '';
  with dsPosList.DataSet do
  try
    First;
    while not Eof do
    begin
      if (FieldByName('Selected').AsBoolean=True) then
      begin
        PosList := PosList + QuotedStr(FieldByName('PosID').AsString) + ',';         
      end;
      Next;
    end;
    if Trim(PosList)<>'' then
      FPosList := '(' + Copy(PosList, 1, Length(PosList)-1) + ')'
    else FPosList := '';
  except
    raise;
  end;

  //if Trim(FPosList)<>'' then
  begin
    ModalResult := mrOk;
  end;
end;

end.
